/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package entity;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Rodrigo
 */
@Entity
@Table(name = "alternativa")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Alternativa.findAll", query = "SELECT a FROM Alternativa a"),
    @NamedQuery(name = "Alternativa.findById", query = "SELECT a FROM Alternativa a WHERE a.id = :id"),
    @NamedQuery(name = "Alternativa.findByDescripcion", query = "SELECT a FROM Alternativa a WHERE a.descripcion = :descripcion"),
    @NamedQuery(name = "Alternativa.findByCorrecta", query = "SELECT a FROM Alternativa a WHERE a.correcta = :correcta")})
public class Alternativa implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID")
    private Integer id;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 512)
    @Column(name = "DESCRIPCION")
    private String descripcion;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 1)
    @Column(name = "CORRECTA")
    private String correcta;
    @OneToMany(mappedBy = "alternativaPareadaCorrecta", fetch = FetchType.EAGER)
    private List<Alternativa> alternativaList;
    @JoinColumn(name = "ALTERNATIVA_PAREADA_CORRECTA", referencedColumnName = "ID")
    @ManyToOne(fetch = FetchType.EAGER)
    private Alternativa alternativaPareadaCorrecta;
    @JoinColumn(name = "PREGUNTA", referencedColumnName = "ID")
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    private Pregunta pregunta;

    public Alternativa() {
    }

    public Alternativa(Integer id) {
        this.id = id;
    }

    public Alternativa(Integer id, String descripcion, String correcta) {
        this.id = id;
        this.descripcion = descripcion;
        this.correcta = correcta;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getDescripcion() {
        return descripcion;
    }

    public void setDescripcion(String descripcion) {
        this.descripcion = descripcion;
    }

    public String getCorrecta() {
        return correcta;
    }

    public void setCorrecta(String correcta) {
        this.correcta = correcta;
    }

    @XmlTransient
    public List<Alternativa> getAlternativaList() {
        return alternativaList;
    }

    public void setAlternativaList(List<Alternativa> alternativaList) {
        this.alternativaList = alternativaList;
    }

    public Alternativa getAlternativaPareadaCorrecta() {
        return alternativaPareadaCorrecta;
    }

    public void setAlternativaPareadaCorrecta(Alternativa alternativaPareadaCorrecta) {
        this.alternativaPareadaCorrecta = alternativaPareadaCorrecta;
    }

    public Pregunta getPregunta() {
        return pregunta;
    }

    public void setPregunta(Pregunta pregunta) {
        this.pregunta = pregunta;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Alternativa)) {
            return false;
        }
        Alternativa other = (Alternativa) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Alternativa[ id=" + id + " ]";
    }
    
}
